#ifndef __LUOO_SINGLETON_HPP__
#define __LUOO_SINGLETON_HPP__

#include <boost/scoped_ptr.hpp>
#include <boost/thread/once.hpp>
#include <boost/noncopyable.hpp>

namespace luoo
{
	template <class T>
	class singleton : private boost::noncopyable
	{
	public:
		static T& get_instance()
		{
			boost::call_once(init, flag_);
			return *self_;
		}
		static T* get_instance_ptr()
		{
			boost::call_once(init, flag_);
			return &*self_;
		}
		static void init()
		{
			self_.reset(new T());
		}

	protected:
		~singleton() {}
		singleton() {}

	private:
		static boost::scoped_ptr <T> self_;
		static boost::once_flag flag_;
	};
	template <class T> boost::scoped_ptr<T> singleton<T>::self_(0);
	template <class T> boost::once_flag singleton<T>::flag_ = BOOST_ONCE_INIT;

}// namespace luoo
#endif//__LUOO_SINGLETON_HPP__